package com.baosu.config;

import com.baosu.Exception.BusinessException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("user");
        System.out.println("loginUser = " + loginUser);
        if(loginUser == null){
            response.setStatus(401);
            response.setHeader("url", "/login");
            throw new BusinessException(false, "无权访问");
        }else{
            return true;
        }
    }

}
